package  com.pcbly.web.business.user;

/**
* @author carl.song
* Copyright (c) 2010 Lightsoft, International.
* All rights reserved.
*
*/

import java.util.HashMap;
import java.util.List;

import com.pcbly.web.persistence.user.UserSchoolDao;
import com.pcbly.web.persistence.table.ColumnDao;
import com.pcbly.web.bean.user.UserSchoolBean;
import com.pcbly.web.bean.table.ColumnBean;
import com.pcbly.web.business.BaseServiceImp;
import com.pcbly.web.components.hibernate.support.Page;
import com.pcbly.web.components.form.AbstractAnalyseCommonDataExt;
import com.pcbly.web.components.form.AnalyseCommonDataExtCreate;
import com.pcbly.web.components.form.AnalyseCommonDataExtEdit;
import com.pcbly.web.components.form.AnalyseCommonDataExtView;

 
public class UserSchoolServiceImp extends BaseServiceImp<UserSchoolBean> implements UserSchoolService {
	 public UserSchoolServiceImp() {
		super();
		// TODO Auto-generated constructor stub
	}
	private UserSchoolDao userSchoolDao;
	
	private ColumnDao columnDao;

	public void setColumnDao(ColumnDao columnDao) {
		this.columnDao = columnDao;
	}
	
	public void setUserSchoolDao(UserSchoolDao userSchoolDao) {
		this.userSchoolDao = userSchoolDao;
	}
	
	@Override
	public UserSchoolBean getUserSchoolBeanById(String id) throws Exception {
		// TODO Auto-generated method stub
		return userSchoolDao.get(UserSchoolBean.class,id);
	}
	
	@Override
	public void removeUserSchoolBeanById(String id) throws Exception{
		userSchoolDao.removeUserSchoolBeanById(id);
	}
	
	@Override
	public void removeUserSchoolBeanByIds(String ids) throws Exception{
		userSchoolDao.removeUserSchoolBeanByIds(ids);
	}
	
	
	@Override
	public UserSchoolBean saveUserSchoolBean(UserSchoolBean user) throws Exception{
		return userSchoolDao.saveUserSchoolBean(user);
	}
	
	@Override
	public UserSchoolBean updateUserSchoolBean(UserSchoolBean user) throws Exception{
		userSchoolDao.saveObject( user);
		return user;
	}
	public Page<UserSchoolBean>  findUserSchoolBeanByCond(UserSchoolBean bean,
			Page<UserSchoolBean> page, String orderByName, boolean asc)
			throws Exception{
		return userSchoolDao.findUserSchoolBeanByCond(
				bean, page, orderByName, asc);
	}
	
	@Override
	public String findUserSchoolBeanExtCreate(String tableName) throws Exception {
		// TODO Auto-generated method stub
		List<ColumnBean> columnList = columnDao
				.findColumnBeansByTableName(tableName);
		AbstractAnalyseCommonDataExt common = new AnalyseCommonDataExtCreate();
		common.setColumnList(columnList);
		return common.execute().toString();
	}

	@Override
	public String findUserSchoolBeanExtEdit(String tableName, String id)
			throws Exception {
		// TODO Auto-generated method stub
		List<HashMap<String, String>> dataList = userSchoolDao
				.findCommnonDataBeanExt(tableName, id);
		List<ColumnBean> columnList = columnDao
				.findColumnBeansByTableName(tableName);
		AbstractAnalyseCommonDataExt common = new AnalyseCommonDataExtEdit();
		common.setDataList(dataList);
		common.setColumnList(columnList);
		return common.execute().toString();
	}

	@Override
	public String findUserSchoolBeanExtView(String tableName, String id)
			throws Exception {
		// TODO Auto-generated method stub
		List<HashMap<String, String>> dataList = userSchoolDao
				.findCommnonDataBeanExt(tableName, id);
		List<ColumnBean> columnList = columnDao
				.findColumnBeansByTableName(tableName);
		AbstractAnalyseCommonDataExt common = new AnalyseCommonDataExtView();
		common.setDataList(dataList);
		common.setColumnList(columnList);
		return common.execute().toString();
	}

	@Override
	public void saveUserSchoolBeanExt(String sql) throws Exception {
		// TODO Auto-generated method stub
		userSchoolDao.saveCommnonDataBeanExt(sql);
	}

	@Override
	public boolean getHasUserSchoolBeanExtData(String tableName, String id)
			throws Exception {
		// TODO Auto-generated method stub
		return userSchoolDao.getHasCommnonDataBeanExt(tableName, id);
	}
}
